﻿
Imports System.Data.OleDb
Partial Public Class AddPlace
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_AddPlace_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_AddPlace.Click

        Dim conn = New OleDbConnection(ConfigurationManager.ConnectionStrings("PlacesConnectionString").ToString())

        Dim sql As String = "INSERT INTO locations(Picture,Area,City,Country,ViewOnGoogleMaps,Description,UserName,Views) Values (@Picture,@Area,@City,@Country,@ViewOnGoogleMaps,@Description,@UserName,@Views)"

        Dim fileLocationOnServer = Request.MapPath("Images/" & f_Picture.FileName)

        f_Picture.SaveAs(fileLocationOnServer)

        Dim relativePath As String = "Images/" & f_Picture.FileName


        Dim dbcmd = New OleDbCommand(sql, conn)

        dbcmd.Parameters.AddWithValue("@Picture", relativePath)
        dbcmd.Parameters.AddWithValue("@Area", Me.tb_Area.Text)
        dbcmd.Parameters.AddWithValue("@City", tb_City.Text)
        dbcmd.Parameters.AddWithValue("@Country", tb_Country.Text)
        dbcmd.Parameters.AddWithValue("@View On Google Maps", tb_MapLink.Text)
        dbcmd.Parameters.AddWithValue("@Description", tb_Description.Text)
        dbcmd.Parameters.AddWithValue("@UserName", User.Identity.Name)
        dbcmd.Parameters.AddWithValue("@Views", 0)
        conn.Open()

        dbcmd.ExecuteNonQuery()
        Response.Redirect("list.aspx")


    End Sub
End Class